const data = require('../../db.js');
const router = require('express').Router();
const cty = 'library';
const ctys = 'librarys';
const ctts = 'push'
router.get(`/${cty}`,(req,res)=>{
    
    //   console.log(req.query);
      const pagesize = req.query.pagesize;
      const pagenum = Number(req.query.pagenum);
      const size = (pagenum-1)*Number(pagesize)
    //   console.log(size)
      const sql = 'select count(*) total from libiary;select * from libiary limit ?,?'
      data.query('select count(*) total from library;select * from library limit ?,?',[Number(size),Number(pagesize)],(error,result)=>{
        // console.log(result[0]);
          if(error){
              res.json({
                  code:'300'
              })
          }else{
              res.json({
                  code:'200',
                  data:result[1],
                  total:result[0]
              })
          }
          
      })
    })
// 右侧瀑布流数据
router.get(`/${ctys}`,(req,res)=>{
    data.query('select * from ebook limit 9',(error,result)=>{
        if(error){
            res.json({
                code:'401'
            })
        }else{
            res.json({
                code:'206',
                data:result
            })
        }
        // console.log(result)
    })
})
router.get(`/${ctts}`,(req,res)=>{
    data.query('select * from ebook limit 9',(error,result)=>{
        if(error){
            res.json({
                code:'401'
            })
        }else{
            res.json({
                code:'206',
                data:result
            })
        }
        console.log(result)
    })
})
module.exports=router;